package com.pswv2.backstage.user.imp;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pswv2.backstage.user.service.UserService;
import com.pswv2.bub.bsc.dao.po.User;
import com.pswv2.util.ExtraSpringHibernateTemplate;


@Service
@SuppressWarnings("unchecked")
public class UserServiceImpl implements UserService {
	private static Class<?> poc = User.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;

	@Override
	public User queryByAccount(String account) {
		DetachedCriteria detached = DetachedCriteria.forClass(poc);
		detached.add(Restrictions.eq("account", account));
		return extraSpringHibernateTemplate.findFirstOneByCriteria(detached);
	}

	@Override
	public User queryById(Integer id) {
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "userId", id);
	}

	@Override
	public List<User> queryAll() {
		// TODO Auto-generated method stub
		List<User> ls=(List<User>) extraSpringHibernateTemplate.findAll(poc);
		return ls;
	}
}
